package com.atguigu.gmall.seckill.task;

import com.atguigu.gmall.seckill.entity.SeckillGoods;
import com.atguigu.gmall.seckill.service.SeckillGoodsService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

@Component
@Slf4j
public class CacheHotPreTask {

    @Autowired
    private SeckillGoodsService seckillGoodsService ;

    @XxlJob(value = "localCacheJobHandler")
    public void localCacheHotPre() {

        // 查询当前参与秒杀获取的商品数据
        List<SeckillGoods> seckillGoods = seckillGoodsService.selectAllToDaySeckillGoods() ;
        log.info("seckillGoods.... {}" , seckillGoods.toString() );

        // 把查询到的数据存储到本地缓存
        seckillGoodsService.saveDataToLocalCache(seckillGoods) ;
        log.info("同步数据到本地缓存完毕...");

    }

    @XxlJob(value = "disCacheJobHandler")
    public void disCacheHotPre() {

        // 查询当前参与秒杀获取的商品数据
        List<SeckillGoods> seckillGoods = seckillGoodsService.selectAllToDaySeckillGoods() ;
        log.info("seckillGoods.... {}" , seckillGoods.toString() );

        // 把查询到的数据存储到Redis中
        seckillGoodsService.saveDataToRedis(seckillGoods);
        log.info("同步数据到Redis完毕...");

    }

}
